﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace Gencode.PrsWeb.App
{
	public class AppGlobal
	{
		private static string m_applicationName;
		private static string m_version;
		private static string m_email;

		/// <summary>
		/// Sets the OdbcConnection
		/// </summary>
		/// <returns>Fals if an error occured</returns>
		public static bool SetDatabaseConection()
		{
			string dsn = ConfigurationManager.AppSettings.Get("DatasourceName");
			string database = ConfigurationManager.AppSettings.Get("Database");
			string user = ConfigurationManager.AppSettings.Get("User");
			string pwd = ConfigurationManager.AppSettings.Get("Password");

			Gencode.Common.SQL.DatabaseConection.ODBCConnetionString = "DSN=" + dsn + ";UID=" + user + ";PWD=" + pwd + ";Database=" + database + ";";
			return Gencode.Common.SQL.DatabaseConection.InitOdbcConnection();
		}

		#region Properties

		/// <summary>
		/// Checks if the OdbcConnection ist set
		/// </summary>
		public static bool IsOdbcConection
		{
			get
			{
				if (Gencode.Common.SQL.DatabaseConection.ODBCConnection != null)
					return true;

				return false;
			}
		}

		public static string ApplicationName
		{
			get
			{
				if (m_applicationName == null || m_applicationName == string.Empty)
					m_applicationName = ConfigurationManager.AppSettings.Get("ApplicationName");

				return m_applicationName;
			}
		}

		public static string ApplicationVersion
		{
			get
			{
				if (m_version == null || m_version == string.Empty)
					m_version = ConfigurationManager.AppSettings.Get("ApplicationVersion");

				return m_version;
			}
		}

		public static string ApplicationEmail
		{
			get
			{
				if (m_email == null || m_email == string.Empty)
					m_email = ConfigurationManager.AppSettings.Get("ApplicationEmail");

				return m_email;
			}
		}

#endregion

	}
}
